package com.ce.pms.house.web;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.charge.service.IAccountService;
import com.ce.pms.charge.service.IMeterDataRegisterService;
import com.ce.pms.charge.vo.AccountVO;
import com.ce.pms.charge.vo.OriginalMeterDataVO;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.service.IDataRightService;
import com.ce.pms.common.service.ISysrefcodeService;
import com.ce.pms.customer.service.ICustomerService;
import com.ce.pms.customer.service.IProRightService;
import com.ce.pms.customer.vo.ProRightVO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.exception.UILayerException;
import com.ce.pms.house.model.GoodsRecordDomain;
import com.ce.pms.house.model.HouseDomain;
import com.ce.pms.house.service.IBuildingService;
import com.ce.pms.house.service.IGoOutService;
import com.ce.pms.house.service.IHouseService;
import com.ce.pms.house.service.IProRightChangeService;
import com.ce.pms.house.vo.AssessorVO;
import com.ce.pms.house.vo.BuildingVO;
import com.ce.pms.house.vo.ExamineApproveVO;
import com.ce.pms.house.vo.GoOutVO;
import com.ce.pms.house.vo.ReasonVO;
import com.ce.util.BlankUtil;
import com.sitechasia.webx.components.xtable.util.ExtremeUtils;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.support.Page;

public class ProRightModificationAction extends PmsBaseAction {

	// 产权变更Service
	private IProRightChangeService proRightChangeService;

	// 产权Service
	private IProRightService proRightService;

	// 走表Service
	private IMeterDataRegisterService meterDataRegisterService;

	private ISysrefcodeService sysrefcodeService;

	// 房屋Service
	private IHouseService houseService;

	// 客户Service
	private ICustomerService customerService;

	// 楼栋Service
	private IBuildingService buildingService;

	// 帐户service
	private IAccountService accountService;

	// 退伙Service
	private IGoOutService goOutService;

	private IDataRightService dataRightService;

	public void setDataRightService(IDataRightService dataRightService) {
		this.dataRightService = dataRightService;
	}

	public ProRightModificationAction(){}

	/**
	 * 功能描述:  初始化产权变更主页面<br>
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initProRightModificationListMain(){

        List<BuildingVO> buildings = buildingService.getAllBuildingList();
        setAttribute("buildings", buildings);
		return "proRightModificationMain";
	}

	/**
	 * 功能描述:客服部列表查询  <br>
	 * @param houseNumber 房号
	 * @param ownerName 住户姓名
	 * @param pageSize
	 * @param pageNo
	 * @return
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String goOutList(
			@Read(key = "houseNumber") String houseNumber,
			@Read(key = "ownerName")String ownerName,
			@Read(key = "ec_crd",defaultValue="15")int pageSize,
            @Read(key = "ec_p", defaultValue="1")	int pageNo){
			//获取退伙列表
		    /*根据用户userId 查询该用的角色
		     * 1.如果该角色为客服助理 查询所有的信息
		     * 2.如果该角色为客服经理 只能看到自己相关的，除了新建状态
		     * 3.如果该角色为财务经理 条件和客服经理相同
		     */
			String sortStr = ExtremeUtils.getOrderString(getRequest());

			String isFirst = getRequest().getParameter("isFirst");
			if (!BlankUtil.isBlank(isFirst)){
				setAttribute("goOutList", null);
				setAttribute("totalRows", 0);
				return "goOutList";
			}

			Long userId = this.getUserId();
			Page page = proRightChangeService.queryGoOutDoListByPage(houseNumber, ownerName, sortStr, pageNo, pageSize);
			List<GoOutVO> goOutList = page.getResult();
			Long totalRows = page.getTotalCount();

			this.getRequest().setAttribute("goOutList", goOutList);
			this.getRequest().setAttribute("totalRows", totalRows.intValue());
			this.getRequest().setAttribute("houseNumber", houseNumber);
			this.getRequest().setAttribute("ownerName", ownerName);

			this.getRequest().setAttribute("pageNo", page.getCurrentPageNo());
		return "goOutList";
	}

    /**
     * 功能描述：财务经理的列表查询
     * @param houseNumber
     * @param houseHolderName
     * @param pageSize
     * @param pageNo
     * @return
     */
	public String goOutListTwo(@Read(key = "houseNumber") String houseNumber,
		    @Read(key = "ownerName")String ownerName,
		    @Read(key = "ec_crd",defaultValue="15")int pageSize,
            @Read(key = "ec_p", defaultValue="1")	int pageNo){
		goOutList(houseNumber,ownerName,pageSize,pageNo);
		return "goOutListTwo";
	}

	/**
	 * 功能描述：查询产权变更历史列表
	  * Create author:zhanghongli <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 * @param buildingId 楼栋Id
	 * @param houseNumber 房号
	 */
    public String proRightModificationList(
    		 @Read(key = "buildingId")Long buildingId,
    		 @Read(key = "houseNumber")String houseNumber,
    		 @Read(key = "ec_crd",defaultValue="15")int pageSize,
    		 @Read(key = "ec_p",defaultValue="1") int pageNo){
    	 String isFirst =	this.getRequest().getParameter("isFirst");
    	 if (!BlankUtil.isBlank(isFirst)){
    		 this.getRequest().setAttribute("proRightList", null);
        	 this.getRequest().setAttribute("totalRows", 0);
        	 this.getRequest().setAttribute("houseNumber", null);
        	 this.getRequest().setAttribute("buildingId", null);
        	 return "proRightModificationList";
    	 }

    	 String orderStr = ExtremeUtils.getOrderString(this.getRequest());
    	 Long userId = this.getUserId();
    	 if(BlankUtil.isBlank(buildingId)){
    		 buildingId = new Long(0);
    	 }
    	 Page page =  proRightChangeService.queryHisGoOutDoListByPage(buildingId, houseNumber, orderStr, userId, pageNo, pageSize);
    	 Long totalRows = page.getTotalCount();
    	 List<GoOutVO> proRightList = page.getResult();
    	 this.getRequest().setAttribute("proRightList", proRightList);
    	 this.getRequest().setAttribute("totalRows", totalRows.intValue());
    	 this.getRequest().setAttribute("houseNumber", houseNumber);
    	 this.getRequest().setAttribute("buildingId", buildingId);
    	 return "proRightModificationList";
     }

	/**
	 * 功能描述:  初始化增加退伙申请页面<br>
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initGoOutAdd(){
		//获取当前日期
	    this.setAttribute("currentDate", this.getCurrentDate());
 		//加载交房时抄表，验房，物品移交的异常信息
		loadReasonList();
		return "goOutAdd";
	}

	/**
	 * 功能描述:  新增退伙记录
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-28  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
    public String addGoOut(@Read GoOutVO goOutVO){

    	//提交时需要计算该房间需要的费用
    	goOutVO.setCreatorId(this.getUserId());
    	String owner = houseService.getOwnerNameBy(goOutVO.getHouseNumber()); //获取业主姓名
    	goOutVO.setClients(owner);
    	Map<String,OriginalMeterDataVO> meterData = meterDataRegisterService.findMeterDataVOBy(goOutVO.getHouseNumber()); //获取走表数据
    	OriginalMeterDataVO lastWaterVO = meterData.get(SysrefcodeDO.HM_WATER_METER_TYPE_CODE);  //上次水表
    	goOutVO.setCopyMeterWaterPreId(lastWaterVO.getChargeDataId());
    	goOutVO.setCopyMeterWaterPreReading(lastWaterVO.getThisReading());
    	OriginalMeterDataVO lastAmmterVO = meterData.get(SysrefcodeDO.HM_AMMETER_METER_TYPE_CODE); //上次电表
    	goOutVO.setCopyMeterAmmeterPreId(lastAmmterVO.getChargeDataId());
    	goOutVO.setCopyMeterAmmeterPreReading(lastAmmterVO.getThisReading());
    	goOutVO.setSysdate(proRightChangeService.getDataBaseDate());

    	try {
    		proRightChangeService.addGoOutRequisition(goOutVO);
		} catch (BusinessException e) {
			throw new UILayerException(e.getMessage(),BusinessException.WARNING);
		}
    	setAttribute("flag", "addGoOut");
    	return "onlyRefresh";
    }

	/**
	 * 功能描述: 加载交房时抄表，验房，物品移交的异常信息<br>
	 * Create author:黄彦军 <br>
	 * Create on:2008-9-9  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private void loadReasonList(){
		 //查询抄表据异常
	    List<ReasonVO> meterReasonList = goOutService
				.getReasonDefDoList(SysrefcodeDO.CS_REASON_DEF_REASON_TYPE_COPY_METER);

	    setAttribute("meterReasonList", replaceReasonString(meterReasonList));
  	    setAttribute("meterReasonListSize", meterReasonList.size());

  	    //查询验房异常
  	    List<ReasonVO> checkHouseReasonList = goOutService
				.getReasonDefDoList(SysrefcodeDO.CS_REASON_DEF_REASON_TYPE_CHECK_HOUSE);
  	    setAttribute("checkHouseReasonList",  replaceReasonString(checkHouseReasonList));
  	    setAttribute("checkHouseReasonListSize", checkHouseReasonList.size());

  	    //查询物品移交异常
  	    List<ReasonVO> handoverReasonList = goOutService
				.getReasonDefDoList(SysrefcodeDO.CS_REASON_DEF_REASON_TYPE_GOODS_TRANSFER);
  	    setAttribute("handoverReasonList",  replaceReasonString(handoverReasonList));
	    setAttribute("handoverReasonListSize", handoverReasonList.size());
	}

	/**
	 * 功能描述: 将异常描述中的 单引号 ', 又引号 "  进行转义<br>
	 * @param list
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2009-11-24  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private List<ReasonVO>  replaceReasonString(List<ReasonVO> list){
		List<ReasonVO> temp = new ArrayList<ReasonVO>();
		if (BlankUtil.isBlank(list)) {
			return null;
		}

		for (ReasonVO reasonVO : list) {
			String copyMeterReasonName = reasonVO.getDescription();
			if (!BlankUtil.isBlank(copyMeterReasonName)) {

				copyMeterReasonName = copyMeterReasonName.replaceAll("'", "&apos").replaceAll("\\\"",
						"&quot");

				reasonVO.setDescription(copyMeterReasonName);
			}
			temp.add(reasonVO);
		}
		return temp;
	}


	/**
	 * 功能描述: 初始化修改退伙申请页面<br>
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-14 <br>
	 * Edit author: <br>
	 * Edit on: <br>
	 * Why: <br>
	 */
	public String initGoOutEdit(@Read(key = "goOutId") Long goOutId){

		// 根据 退伙Id 查询退伙信息
		GoOutVO goOut = proRightChangeService.findGoOutVOById(goOutId);
		this.getRequest().setAttribute("goOut", goOut);
		// 加载交房时抄表，验房，物品移交的异常信息
		this.loadReasonList();
		String currentDate = this.getCurrentDate();
		this.getRequest().setAttribute("currentDate", currentDate);

		return "goOutEdit";
	}

	/**
	 * 功能描述:  修改退伙审批表保存并提交退伙审批表
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-28  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
    public String editGoOut(@Read GoOutVO goOutVO){
    	 //把修改后的审伙审批表根据数据流情况保存到数据库，并刷新退伙列表信息
    	 goOutVO.setModifierDate(proRightChangeService.getDataBaseDate());
    	 goOutVO.setModifierId(this.getUserId());
    	 proRightChangeService.editGoOutRequisition(goOutVO);
    	 this.getRequest().setAttribute("flag","editGoOut");
    	 return "onlyRefresh";
     }

	/**
	 * 功能描述:  初始化退伙手续  详细  页面(客服部门)<br>
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initGoOutDetail(@Read(key = "keyword")Long keyword){
	   // 根据退伙申请Id(keyword)查询退伙信息,退伙审核信息列表
		GoOutVO goOut = proRightChangeService.findGoOutVOById(keyword);
		List examineList = this.findExamineInfo(keyword);
		this.getRequest().setAttribute("examineList", examineList);
		this.getRequest().setAttribute("out", goOut);
		return "goOutDetail";
	}

	/**
	 * 功能描述:  初始化退伙费用  详细  页面(财务经理)<br>
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-29  <br>
	 * @param keyword 退伙审核Id<br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initGoOutExamineDetail(@Read(key = "keyword")Long keyword){

		GoOutVO goOutVO = proRightChangeService.findGoOutVOById(keyword);
		Long houseId = goOutVO.getHouseId(); //获取房号
		this.getChargeInfo(houseId);
		List<ExamineApproveVO> examineList = this.findExamineInfo(keyword);
		this.getRequest().setAttribute("examineList", examineList);
		return "goOutExamineDetail";

	 }

	 /**
	 * 功能描述:  初始退伙手续  审核  页面(客服经理)<br>
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initGoOutExamine(@Read(key = "goOutId")Long goOutId){

	    //根据退伙Id查询退伙信息
	    GoOutVO goOutVO = proRightChangeService.findGoOutVOById(goOutId);
		this.getRequest().setAttribute("goOut",goOutVO);
		this.getRequest().setAttribute("currentDate", this.getCurrentDate());
		return "goOutExamine";
	}

	/**
	 * 功能描述:  初始化费用  审核  页面(财务经理)<br>
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initChargeExamine(@Read(key = "goOutId")Long goOutId){
		//根据退伙Id查询房屋Id
		GoOutVO goOutVO = proRightChangeService.findGoOutVOById(goOutId);

		Long houseId = goOutVO.getHouseId(); //获取房号
		this.getChargeInfo(houseId);
		List<ExamineApproveVO> examineList = this.findExamineInfo(goOutId);

		this.getRequest().setAttribute("examineList", examineList);
		this.getRequest().setAttribute("goOutId",goOutId);
		this.getRequest().setAttribute("currentDate", this.getCurrentDate());
		this.getRequest().setAttribute("outDate", goOutVO.getOutDate());

		return "chargeExamine";
	}

    /**
     * 功能描述:进行退伙审核的必要条件检查  <br>
     * @param keyword 退伙ID
     * Create author:黄彦军 <br>
     * Create on:2008-9-11  <br>
     * Edit author:  <br>
     * Edit on:    <br>
     * Why:     <br>
     */
    public void checkAudit(@Read(key = "keyword")Long goOutId,
    		 					@Read(key = "type")String type){
    	 try {
       		if("001".equals(type)){//客服经理
       			proRightChangeService.checkAuditing(goOutId, SysrefcodeDO.HM_EXAMINE_APPROVE_USER_ROLE_CLIENT,this.getUserId());
       		}else if ("002".equals(type)){//财务经理
       			proRightChangeService.checkAuditing(goOutId, SysrefcodeDO.HM_EXAMINE_APPROVE_USER_ROLE_FINANCE,this.getUserId());
       		}
   		} catch (BusinessException e) {
   			throw new UILayerException(e.getMessage(), BusinessException.WARNING);
   		}
   		this.renderText("true");
     }

     /**
 	 * 功能描述:  进行退伙审核操作
 	 * Create author:zhanghongli <br>
 	 * Create on:2008-8-26  <br>
 	 * Edit author:  <br>
 	 * Edit on:    <br>
 	 * Why:     <br>
 	 */
    public String goOutAudit(@Read ExamineApproveVO examineVO,@Read (key = "type")String type){

   	  try {
			examineVO.setUserId(this.getUserId());
			//examineVO.setExamineDate(new Date());

			// 判断是否通过审核
			if ("001".equals(examineVO.getExamineActionCode())) {
				examineVO
						.setExamineActionCode(SysrefcodeDO.HM_EXAMINE_APPROVE_AUDITING_PASS);
			} else if ("002".equals(examineVO.getExamineActionCode())) {
				examineVO
						.setExamineActionCode(SysrefcodeDO.HM_EXAMINE_APPROVE_AUDITING_NOPASS);
			}

			if ("001".equals(type)) {// 客服经理
				proRightChangeService.goOutAuditing(examineVO,
						SysrefcodeDO.HM_EXAMINE_APPROVE_USER_ROLE_CLIENT);
				this.getRequest().setAttribute("flag", "clientAudit");
			} else if ("002".equals(type)) {// 财务经理
				proRightChangeService.goOutAuditing(examineVO,
						SysrefcodeDO.HM_EXAMINE_APPROVE_USER_ROLE_FINANCE);
				this.getRequest().setAttribute("flag", "financeAudit");
			}
		} catch (BusinessException e) {
			throw new UILayerException(e.getMessage(),
					BusinessException.WARNING);
		}
 		return "onlyRefresh";
     }

     /**
	 * 功能描述: 进行反审核条件检查
	 * Create author:黄彦军 <br>
     * Create on:2008-9-10 <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
    public void checkAntiAudit(@Read(key = "keyword")Long goOutId,
     		  @Read (key = "type") String type){
      	 try {
      		if("001".equals(type)){//客服经理
      			proRightChangeService.checkReverseAuditing(goOutId, SysrefcodeDO.HM_EXAMINE_APPROVE_USER_ROLE_CLIENT,this.getUserId());
      		}else if ("002".equals(type)){//财务经理
      			proRightChangeService.checkReverseAuditing(goOutId, SysrefcodeDO.HM_EXAMINE_APPROVE_USER_ROLE_FINANCE,this.getUserId());
      		}
  		} catch (BusinessException e) {
  			throw new UILayerException(e.getMessage(), BusinessException.WARNING);
  		}
  		this.renderText("true");
       }

       /**
   	 * 功能描述: 进行 反审核 操作
   	 * Create author:黄彦军 <br>
     * Create on:2008-9-10 <br>
   	 * Edit author:  <br>
   	 * Edit on:    <br>
   	 * Why:     <br>
   	 */
    public String antiAudit(@Read(key = "goOutId")Long goOutId,
    		  @Read (key = "type") String type){
    	  ExamineApproveVO approveVO = new ExamineApproveVO();
    	  Map<String, ExamineApproveVO>  map = proRightChangeService.findExamineApprovesById(goOutId);
    	  if ("001".equals(type)){
    		  approveVO = map.get("001");
    	  }else if ("002".equals(type)){
    		  approveVO = map.get("002");
    	  }
    	  approveVO.setModifierId(this.getUserId());
    	  approveVO.setModifierDate(proRightChangeService.getDataBaseDate());
    	  approveVO.setGoOutId(goOutId);
     	 try {
     		if("001".equals(type)){//客服经理
     			proRightChangeService.goOutReverseAuditing(approveVO,SysrefcodeDO.HM_EXAMINE_APPROVE_USER_ROLE_CLIENT);
     			this.getRequest().setAttribute("flag", "supportAntiAudit");
     		}else if ("002".equals(type)){//财务经理
     			proRightChangeService.goOutReverseAuditing(approveVO,SysrefcodeDO.HM_EXAMINE_APPROVE_USER_ROLE_FINANCE);
     			this.getRequest().setAttribute("flag", "financeAntiAudit");
     		}
 		} catch (BusinessException e) {
 			throw new UILayerException(e.getMessage(), BusinessException.WARNING);
 		}
 		return "onlyRefresh";
      }

      /**
   	 * 功能描述:  变为 历史业主 操作
   	 * Create author:zhanghongli <br>
   	 * Create on:2008-8-26  <br>
   	 * Edit author:  <br>
   	 * Edit on:    <br>
   	 * Why:     <br>
   	 */
    public String changeHistoryOwner(@Read(key = "keyword")Long keyword){
  		 GoOutVO goOutVO =	proRightChangeService.findGoOutVOById(keyword);
      	 // 根据退伙Id 查询房屋Id 根据房屋Id 查询该房屋业主帐户（银行账户）是否为0,只有为0的情况才能进行下步操作
      	 Long houseId = goOutVO.getHouseId();
      	 BigDecimal balance = accountService.getBalance(houseId);
      	 balance = balance.setScale(2,BigDecimal.ROUND_HALF_DOWN);
      	 BigDecimal zero = new BigDecimal(0).setScale(2,BigDecimal.ROUND_HALF_DOWN);
      	 if (!balance.equals(zero)){
      		 this.getRequest().setAttribute("flag", "moneyNotZero");
      		 return "onlyRefresh";
      	 }

      	 //变为历史业主
      	 proRightChangeService.changeToHisOwers(keyword,this.getUserId());
      	 this.getRequest().setAttribute("flag", "toHisOwersOK");
      	 return "onlyRefresh";
       }

    /**
     * 功能描述: 进行提交 <br>
     * @param goOutId
     * @return
     * Create author:黄彦军 <br>
     * Create on:2008-11-21  <br>
     * Edit author:  <br>
     * Edit on:    <br>
     * Why:     <br>
     */
    public String changeSubmit(@Read(key="goOutId") Long goOutId){
    	proRightChangeService.referGoOutRequisition(goOutId, this.getUserId());
    	getRequest().setAttribute("flag", "changeSubmit");
    	return "onlyRefresh";
    }

   /**
	 * 功能描述:判断退伙 状态 <br>
	 *
	 * @param status 状态编码
	 * Create author:黄彦军 <br>
	 * Create on:2008-9-11 <br>
	 * Edit author: <br>
	 * Edit on: <br>
	 * Why: <br>
	 */
	public void checkGoOutStatus(@Read(key = "goOutId")Long goOutId) {
		GoOutVO outVO = proRightChangeService.findGoOutVOById(goOutId);
		String status = outVO.getStatuCode();
		if (status.equals(SysrefcodeDO.HM_GO_OUT_FLOW_AUDIT_NEW)) {// 新建
			this.renderText("new");
		} else if (status.equals(SysrefcodeDO.HM_GO_OUT_FLOW_AUDIT_WAIT)) {// 待审核
			this.renderText("wait");
		} else if (status.equals(SysrefcodeDO.HM_GO_OUT_FLOW_AUDIT_DO)) {// 审核中
			this.renderText("do");
		} else if (status.equals(SysrefcodeDO.HM_GO_OUT_FLOW_AUDIT_FINISH)) {// 审核完毕
			this.renderText("finish");
		} else if (status.equals(SysrefcodeDO.HM_GO_OUT_FLOW_AUDIT_END)) {// 退伙结束
			this.renderText("end");
		}
	}

	/**
	 * 功能描述: 检查房间所有的退伙状态 <br>
	 * @param goOutId
	 * Create author:黄彦军 <br>
	 * Create on:2008-10-6  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void checkHouseGoOutStatus(@Read(key = "goOutId")Long goOutId){
		GoOutVO outVO = proRightChangeService.findGoOutVOById(goOutId);
		String status =proRightChangeService.checkTheHouseNumber(outVO.getHouseId());
		if (status == null || "".equals(status)){
			this.renderText("end");
		}else{
			this.renderText("noEnd");
		}
	}

	/**
	 * 功能描述:根据退伙ID 查询审核信息 <br>
	 *
	 * @param goOutId
	 *            退伙ID
	 * @return Create author:黄彦军 <br>
	 *         Create on:2008-9-16 <br>
	 *         Edit author: <br>
	 *         Edit on: <br>
	 *         Why: <br>
	 */
	private List<ExamineApproveVO>  findExamineInfo(Long goOutId){
		Map<String,ExamineApproveVO>  map= proRightChangeService.findExamineApprovesById(goOutId);
		List<ExamineApproveVO> examineList = new ArrayList<ExamineApproveVO>();
		examineList.add(map.get("001"));
		examineList.add(map.get("002"));
		return examineList;
	}

	/**
	 * 功能描述:根据房屋ID 加载调用收费页面的参数   <br>
	 *
	 * Create author:黄彦军 <br>
	 * Create on:2008-9-16  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private void getChargeInfo(Long houseId){
		ProRightVO proRight= proRightService.getEffectiveProRightByHouseId(houseId);
		Long proRightId =null;
		Long accountId = null;
		if(!BlankUtil.isBlank(proRight)){
			proRightId = proRight.getProRightId();//获取产权ID
			AccountVO accountVO = accountService.getCurrentAccountBy(proRightId,houseId);

			if (!BlankUtil.isBlank(accountVO))
			{
				accountId = accountVO.getAccountId(); //获取有效帐户ID
			}
		}

		this.getRequest().setAttribute("houseId", houseId);
		this.getRequest().setAttribute("proRightId", proRightId);
		this.getRequest().setAttribute("accountId", accountId);
	}

	/**
	 * 功能描述:  初始化移交物品页面<br>
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initGoodsHandOver(@Read(key = "parentFrameId") String parentFrameId,
			@Read(key="goodIds") String goodIds){

        //获取移交物品列表
		List<GoodsRecordDomain> goods =proRightChangeService.getAllGoodsRecords();
		this.getRequest().setAttribute("goodIds", goodIds);
        this.getRequest().setAttribute("goods", goods);
        this.getRequest().setAttribute("parentFrameId", parentFrameId);
		return "chooseGoods";
	}


	/**
	 * 功能描述:  验证房号是否合法:<br>
	 * 1.检查输入的房号是否存在 <br>
	 * 2.检查输入房号的业主是否存在<br>
	 * 3. 检查输入的房号是否已存在审批表中<br>
	 * 4.验证成功返回业主姓名<br>
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void validationHouseNumber(@Read(key = "houseNumber") String houseNumber){
            String flag = null;
            HouseDomain houseDomain = null;
            Long houseId = null;
            if(BlankUtil.isBlank(houseNumber)){
            	flag = "";
            }
            if(flag == null){
            	//检查房号是否存在
                houseDomain =  houseService.getHouseByNumber(houseNumber, true);
            	if(BlankUtil.isBlank(houseDomain)){
            		flag = super.getLocaleMessage("house:pro_right_number_not_exist_exception");
            	}else{//检查是否为产权房
            		if(BlankUtil.isBlank(houseService.getHouseByNumber(houseNumber))){
            			flag = super.getLocaleMessage("house:pro_right_number_not_right_number_exception");
            		}
            	}
            }
            if(flag == null){
            	//检查是否存在业主
            	String owner = houseService.getOwnerNameBy(houseNumber);
            	if(BlankUtil.isBlank(owner)){
            		flag = super.getLocaleMessage("house:pro_right_number_no_owner_exception");
            	}
            }
            if(flag == null){
            	// 检查指定房号的房间是否是单独的产权房间
            	Boolean isShip  = houseService.checkHouseIsLonely(houseNumber);
            	if(!isShip){
            		flag = super.getLocaleMessage("house:pro_right_number_exist_ship_exception");
            	}
            }
            if(flag == null){
            	//检查该房号是否已经存在退伙审批表
				houseId = houseDomain.getKeyword();
            	String code= proRightChangeService.checkTheHouseNumber(houseId);
            	if (!BlankUtil.isBlank(code)){
            			SysrefcodeDO sysrefcodeDO = sysrefcodeService.getSysrefCodesByCode("HM_GO_OUT_FLOW", code);
            			String 	msg = sysrefcodeDO.getName();
            		flag = super.getLocaleMessage("house:pro_right_number_status_pre_exception")+msg+super.getLocaleMessage("house:pro_right_number_status_last_exception");
            	}
            }
            if(flag == null){
            	flag = "true";
            }
            this.renderText(flag);
	}

	/**
	 * 功能描述:  根据房号查询走表数据和业主姓名
	 * Create author:zhanghongli <br>
	 * Create on:2008-8-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void getOwnerNameAndMeterData(@Read(key = "houseNumber")String houseNumber){
		Map<String,OriginalMeterDataVO> meterData =null;



		BigDecimal copyMeterAmmeterPreReading = null;
		BigDecimal copyMeterWaterPreReading = null;

		//当是点击了 录入抄表读数按钮 确发时执行----------
		String flag = this.getRequest().getParameter("isRecordFeel");
		if (!BlankUtil.isBlank(flag) && "true".equals(flag)){
			Long  gooutId = new Long(this.getRequest().getParameter("keyword"));
			GoOutVO goOutVO = proRightChangeService.findGoOutVOById(gooutId);
			 copyMeterWaterPreReading = goOutVO.getCopyMeterWaterPreReading();
			 copyMeterAmmeterPreReading = goOutVO.getCopyMeterAmmeterPreReading();
		}
		//------------------------------------------


		try {
			meterData = meterDataRegisterService.findMeterDataVOBy(houseNumber);
		} catch (Exception e) {
			throw new UILayerException(e.getMessage(),BusinessException.FAILURE);
		}
		StringBuffer meterInfo =  new StringBuffer();
		//处理业主名称
		String owner = houseService.getOwnerNameBy(houseNumber);
		meterInfo.append("{'owner':'").append(owner).append("'");
		//处理水表和电表上次读数


		//不是点击了 录入抄表读数按钮 确发的
		if (BlankUtil.isBlank(copyMeterWaterPreReading) && BlankUtil.isBlank(copyMeterAmmeterPreReading)){
			if (!BlankUtil.isBlank(meterData)){
				if (!BlankUtil.isBlank(meterData.get("001"))){
					meterInfo.append(",").append(getMeterInfoForJson(meterData.get("001")));
				}

				if (!BlankUtil.isBlank(meterData.get("002"))){
					meterInfo.append(",").append(getMeterInfoForJson(meterData.get("002")));
				}
			}
		}else{//是点击了 录入抄表读数按钮 确发的
			meterInfo.append("'type").append("type001").append("':");
			meterInfo.append("{").append("'lastReading':'").append(copyMeterWaterPreReading+"").append("'}");
			meterInfo.toString();

			meterInfo.append("'type").append("type002").append("':");
			meterInfo.append("{").append("'lastReading':'").append(copyMeterAmmeterPreReading+"").append("'}");
			meterInfo.toString();
		}



//		if (!BlankUtil.isBlank(meterData)){
//			if (!BlankUtil.isBlank(meterData.get("001"))){
//				meterInfo.append(",").append(getMeterInfoForJson(meterData.get("001")));
//			}
//			if (!BlankUtil.isBlank(meterData.get("002"))){
//				meterInfo.append(",").append(getMeterInfoForJson(meterData.get("002")));
//			}
//		}



		//处理房屋ID
		HouseDomain houseDomain = houseService.getHouseByNumber(houseNumber);
		meterInfo.append(",'houseId':'").append(houseDomain.getKeyword()).append("'");
		String inDate = this.getInDate(houseDomain.getKeyword());
		meterInfo.append(",'inDate':'");
		meterInfo.append(inDate);
		meterInfo.append("'");
		meterInfo.append("}");
		renderText(meterInfo.toString());
	}

	/**
	 *
	 * 功能描述: 根据房屋Id查询入伙日期
	 * 注意：这里是要调用业务服务类的方法，留一个调用的地方。  <br>
	 * @author 张红丽  <br>
	 * Created on:2008-6-20  <br>
	 */
	private String getInDate(Long houseId){
 		return "";
	}


	/**
	 * 功能描述: 处理水表和电表上次读数 <br>
	 * @param meterDataVO
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-8-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private String getMeterInfoForJson(OriginalMeterDataVO meterDataVO){
		StringBuffer meterInfo = new StringBuffer();
		meterInfo.append("'type").append(meterDataVO.getMeterType()).append("':");
		meterInfo.append("{").append("'lastReading':'").append(meterDataVO.getThisReading()).append("'}");
		return meterInfo.toString();
	}

     /** Function:获取当前日期，并以yyyy-MM-dd HH:mm格式返回
 	 * @return
 	 * Create author:张红丽
 	 * Create on:2008-9-2
 	 * Edit author:
 	 * Edit on:
 	 * Why:
 	 */
 	private String getCurrentDate() {
 		String currentDate="";
 		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
 		currentDate=sf.format(proRightChangeService.getDataBaseDate());
 		return currentDate;
 	}

 	//获取异常列表:需要从Service中获取 参数为异常类型编码
 	protected List<ReasonVO> getReasonList(String type){
 		return null;
 	}

 	//获取移表物品列表
 	protected List<ReasonVO> getGoodsList(){
 		return null;
 	}

 	/** Function:查询审核人列表
 	 * 注:因没集成人事系统,临时方法决定选查询所用户,岗位信息空着不查询,等集成人事系统之后,再修改该代码
 	 * @return
 	 * Create author:张红丽
 	 * Create on:2008-9-2
 	 * Edit author:
 	 * Edit on:
 	 * Why:
 	 */
 	protected List<AssessorVO> getAssessorList(String role){
	   return null;
   }

 	/**
 	 * 功能描述:检查审核人有没有对这个房间的访问权限<br>
 	 *
 	 * Create author:黄彦军 <br>
 	 * Create on:2008-11-28  <br>
 	 * Edit author:  <br>
 	 * Edit on:    <br>
 	 * Why:     <br>
 	 */
 	public void checkExaminer(@Read(key = "userId") Long userId,
 			                   @Read(key = "houseId") Long houseId) {
		boolean flag = dataRightService.getDataRightByUserId(userId, houseId);
		if (flag){
			renderText("true");
		}else{
			renderText("false");
		}

	}

	/* *
	 * 各种验证时所需要的方法
	 */
	/* 新建条件
     *  房间与其它房间不存在合并关系 (不能确定是否有现有的方法)
	 *  修改
	 *  １．条件，只有新建状态的退伙审批表才能进行修改，需要的方法，根据退伙Id返回退伙状态
	 *  提交：同上
	 *  变为历史业主：条件
	 *  1.退伙审批表状态为审核完毕 方法1
	 *  2.业主的所有账户都结清 根据退伙Id查询房查询所有的退伙信息，根据退伙信息中的房屋Id查询该房屋账户信息判断该业主的各账户是否结清
	 *  打印退伙审批表条件
	 *  1.提交后该功能才可以用
	 *  2.该业主还存在挂起或出盘锁定状态的交易(提示信息：该业主还存在挂起或出盘锁定状态状态的交易，不允许打印)
	 *  反审核条件
	 *  1.只能反审核自己审核过的退伙审批表反审核后
	 *  登记新业主条件
	 *  1.退伙审批表为退伙结束
	 *
	 */

	public IHouseService getHouseService() {
		return houseService;
	}

	public void setHouseService(IHouseService houseService) {
		this.houseService = houseService;
	}

	public ICustomerService getCustomerService() {
		return customerService;
	}

	public void setCustomerService(ICustomerService customerService) {
		this.customerService = customerService;
	}

	public IGoOutService getGoOutService() {
		return goOutService;
	}

	public void setGoOutService(IGoOutService goOutService) {
		this.goOutService = goOutService;
	}

	public IBuildingService getBuildingService() {
		return buildingService;
	}

	public void setBuildingService(IBuildingService buildingService) {
		this.buildingService = buildingService;
	}

	public IProRightChangeService getProRightChangeService() {
		return proRightChangeService;
	}

	public void setProRightChangeService(
			IProRightChangeService proRightChangeService) {
		this.proRightChangeService = proRightChangeService;
	}

	public IMeterDataRegisterService getMeterDataRegisterService() {
		return meterDataRegisterService;
	}

	public void setMeterDataRegisterService(
			IMeterDataRegisterService meterDataRegisterService) {
		this.meterDataRegisterService = meterDataRegisterService;
	}

	public IAccountService getAccountService() {
		return accountService;
	}

	public void setAccountService(IAccountService accountService) {
		this.accountService = accountService;
	}

	public IProRightService getProRightService() {
		return proRightService;
	}

	public void setProRightService(IProRightService proRightService) {
		this.proRightService = proRightService;
	}

	public ISysrefcodeService getSysrefcodeService() {
		return sysrefcodeService;
	}

	public void setSysrefcodeService(ISysrefcodeService sysrefcodeService) {
		this.sysrefcodeService = sysrefcodeService;
	}

}
